#include "Input.h"

//Standard library headers
#include <windows.h>

CInput::CInput()
{
    
    //Get the mouse location
	POINT pos;
	
	if (GetCursorPos(&pos) != 0) { 
	    
	    //Save the new mouse position
		mousepos = Vector(pos.x, pos.y);
	    
    }
    
    for (int i=0;i<256;++i) {
        
        oldkeys[i] = false;
        keys[i] = false;
        
    }
    
}

void CInput::CheckInput()
{

	//Store old key states
    /*for (int i=0;i<256;i++){
		
		oldkeys[i] = keys[i];
		
	}*/

    //Get new key states
    for (int i=0;i<256;i++){
		
		oldkeys[i] = keys[i];
		keys[i] = (GetAsyncKeyState(i) & 0x8000);
		
	}

	//Get the mouse location
	POINT pos;
	
	if (GetCursorPos(&pos) != 0) { 
	    
	    //Store the old position of the mouse
	    mouseoldpos = mousepos;
	    
	    //Save the new mouse position
		mousepos = Vector(pos.x, pos.y);
	    
	    //Find the vector of movement
	    mousevector = mousepos - mouseoldpos;
	    
	    //Get the distance moved
	    mousedistance = mousevector.getLength();
	    
	    //If the mouse moved
	    if (mousedistance > 0){
			
			//Store the mouse direction
			mouseangle = mousevector.getAngle();
			
		}
	    
	}
	else{
		
		//Could not load the mouse position so return a rubbish value
		//mousepos = Vector3D(-1, -1, -1);
		
	}

}
